package com.xunyin.modules.mainpart.service.mapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xunyin.common.mapper.CoreMapper;
import com.xunyin.modules.mainpart.domain.TMainPart;
import com.xunyin.modules.mainpart.vo.TMainPartVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Author xunyinyunshang  <3594419785@qq.com>
 * @date 2022-09-09
 */
@Repository
public interface TMainPartMapper extends CoreMapper<TMainPart> {

    @Select("SELECT tp.id as id," +
            " tp.main_name as mainName," +
            " tp.business_id as business_id," +
            " ta1.area_name as provinceName," +
            " ta2.area_name as cityName," +
            " ta3.area_name as countyName," +
            " tp.province_code as provinceCode," +
            " tp.city_code as cityCode," +
            " tp.county_code as countyCode," +
            " tp.remark as remark" +
            " FROM t_main_part tp" +
            " left join t_area_space ta1 on tp.province_code = ta1.area_code " +
            " left join t_area_space ta2 on tp.city_code = ta2.area_code " +
            " left join t_area_space ta3 on tp.county_code = ta3.area_code " +
            " where tp.status = 1 <if test=\"mainName!=null\"> and mainName like CONCAT('%',#{mainName},'%') </if>" +
            " <if test =\"id !=null\">and tp.id=#{id}</if>")
    List<TMainPartVo> getMainList(Page page, @Param("mainName") String mainName, @Param("id") Integer id);
}
